﻿@{
    Layout = "_LayuiAdminLayout";
}
@using Urs.Plugin.Shipping.ByWeight.Models;
@using Urs.Framework;
@using Urs.Core.Infrastructure;

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-tags" data-type="add">添加</button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <p>
                <b>
                    @T("Plugins.Shipping.ByWeight.Formula")
                </b>
                @T("Plugins.Shipping.ByWeight.Formula.Value")
            </p>
            <table id="LAY-resource-list" lay-data="" lay-filter="LAY-resource-list"></table>
            <script type="text/html" id="layuiadmin-app-cont-tagsbar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','form'], function () {
        var table = layui.table
            ,form = layui.form;
        //分类管理
        table.render({
            elem: '#LAY-resource-list'
            , method: 'post'
            , id:'resource-list'
            , url: '@Html.Raw(Url.Action("RatesList", "ShippingByWeight"))' //模拟接口
            , page: true //开启分页
            , even: true
            , limit: 30
            , limits: [15, 30, 50, 100]
            , cols: [[
                { type: 'numbers', fixed: 'left' }
                , { field: 'AreasName', title: '@T("Plugins.Shipping.ByWeight.Fields.AreasName")', minWidth: 250 }
                , { field: 'ShippingMethodName', title: '@T("Plugins.Shipping.ByWeight.Fields.ShippingMethod")',  width: 100 }
                , { field: 'First', title: '@T("Plugins.Shipping.ByWeight.Fields.First")', width: 100 }
                , { field: 'FirstPrice', title: '@T("Plugins.Shipping.ByWeight.Fields.FirstPrice")', width: 100 }
                , { field: 'Plus', title: '@T("Plugins.Shipping.ByWeight.Fields.Plus")', width: 100 }
                , { field: 'PlusPrice', title: '@T("Plugins.Shipping.ByWeight.Fields.PlusPrice")', width: 100 }
                , { title: '操作', width: 220, align: 'center', fixed: 'right', toolbar: '#layuiadmin-app-cont-tagsbar' }
            ]]
            , text: { none: '一条数据也没有^_^' }
        });

        //监听工具条
        table.on('tool(LAY-resource-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Html.Raw(Url.Action("RateDelete", "ShippingByWeight"))', { id: obj.data.Id });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("EditPopup", "ShippingByWeight")?id=' + data.Id
                    , area: ['800px', '600px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            }
        });
        var $ = layui.$, active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("EditPopup", "ShippingByWeight")'
                    , area: ['800px', '600px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
